package src.array;

public class no941 {
    //有效的山脉数组
    public static void main(String[] args) {
        int[] arr = {0,1,2,3,4,5,6,7,8,9};
        System.out.println(validMountainArray(arr));

    }

    //左右指针向中间移，在中间相遇时则为山脉数组。中间到两头必须严格递减
    public static boolean validMountainArray(int[] arr) {
        int n = arr.length;
        int left = 0;
        int right = n - 1;
        while (left < right && arr[left] < arr[left + 1]) {
            left++;
        }
        while (left < right && arr[right] < arr[right - 1]) {
            right--;
        }

        //当指针相遇时，必须在数组中间不能在两边，所以仍要加一个if判断
        if (left == right && left != 0 && right != n-1) {
            return true;
        } else {
            return false;
        }


    }
}
